package com.zmn.oms.services.impl.conf.attachment;

import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.oms.model.entity.conf.attachment.city.ConfOrderAttachmentCity;
import com.zmn.oms.model.entity.conf.attachment.city.ConfOrderAttachmentCityQuery;
import com.zmn.oms.persistence.interfaces.conf.attachment.ConfOrderAttachmentChannelDao;
import com.zmn.oms.persistence.interfaces.conf.attachment.ConfOrderAttachmentCityDao;
import com.zmn.oms.services.interfaces.conf.attachment.ConfOrderAttachmentCityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 附件配置-城市基础接口实现类
 *
 * @author weilai
 * @since 2022-06-08 17:50:43
 **/
@Slf4j
@Service
public class ConfOrderAttachmentCityServiceImpl implements ConfOrderAttachmentCityService {

    private static final String TAG = "附件配置-城市基础服务接口";

    @Resource
    private ConfOrderAttachmentCityDao confOrderAttachmentCityDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param id id
     * @author weilai
     * @since 2022-06-08 17:50:43
     **/
    @Override
    public ConfOrderAttachmentCity findById(Integer id) {

        if (Objects.isNull(id)) {
            log.error("[{}],根据id查询数据id为null", TAG);
            return null;
        }
        return confOrderAttachmentCityDao.findById(id);
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query 查询对象
     * @author weilai
     * @since 2022-06-08 17:50:43
     **/
    @Override
    public List<ConfOrderAttachmentCity> listPageByQuery(ConfOrderAttachmentCityQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        Integer count = countByQuery(query);
        query.setTotalCount(count);
        return confOrderAttachmentCityDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author weilai
     * @since 2022-06-08 17:50:43
     **/
    @Override
    public List<ConfOrderAttachmentCity> listByQuery(ConfOrderAttachmentCityQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }

        return confOrderAttachmentCityDao.listByQuery(query);
    }

    @Override
    public List<ConfOrderAttachmentCity> listBatch(List<Integer> confOrderAttachmentIds) {
        return confOrderAttachmentCityDao.listBatch(confOrderAttachmentIds);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author weilai
     * @since 2022-06-08 17:50:43
     **/
    @Override
    public Integer countByQuery(ConfOrderAttachmentCityQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return confOrderAttachmentCityDao.countByQuery(query);
    }


    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param ConfOrderAttachmentCity 待修改数据
     * @return java.lang.Integer
     * @author weilai
     * @since 2022-06-08 17:50:43
     **/
    @Override
    public Integer updateByKey(ConfOrderAttachmentCity ConfOrderAttachmentCity) {

        if (Objects.isNull(ConfOrderAttachmentCity.getId())) {
            log.error("[{}],根据id修改数据,ConfOrderAttachmentCity为null", TAG);
            return null;
        }
        return confOrderAttachmentCityDao.updateByKey(ConfOrderAttachmentCity);
    }

    /**
     * 描述: 新增数据
     *
     * @param ConfOrderAttachmentCity 待新增数据
     * @return java.lang.Integer 主键key
     * @author weilai
     * @since 2022-06-08 17:50:43
     **/
    @Override
    public Integer insert(ConfOrderAttachmentCity ConfOrderAttachmentCity) {

        if (Objects.isNull(ConfOrderAttachmentCity)) {
            log.error("[{}],新增数据,ConfOrderAttachmentCity为null", TAG);
            return null;
        }
        return confOrderAttachmentCityDao.insert(ConfOrderAttachmentCity);
    }

    @Override
    public Integer insertBatch(List<ConfOrderAttachmentCity> confOrderAttachmentCities) {
        if (CollectionUtil.isNullOrEmpty(confOrderAttachmentCities)) {
            log.error("[{}],批量新增数据,ConfOrderAttachmentChannels", TAG);
            return null;
        }
        return confOrderAttachmentCityDao.insertBatch(confOrderAttachmentCities);
    }

    /**
     * 描述: 根据主键删除数据
     *
     * @param id
     * @return: 执行结果码
     * @auther: weilai
     * @since: 2022-06-08 17:50:43
     */
    @Override
    public Integer deleteByKey(Integer id) {

        if (Objects.isNull(id)) {
            log.error("[{}],根据id删除数据,id为null", TAG);
            return null;
        }
        return confOrderAttachmentCityDao.deleteByKey(id);
    }

    @Override
    public Integer deleteByAttachmentId(Integer attachmentId) {
        if (Objects.isNull(attachmentId)) {
            log.error("[{}],根据attachmentId删除数据,attachmentId为null", TAG);
            return null;
        }
        return confOrderAttachmentCityDao.deleteByAttachmentId(attachmentId);
    }

}